package wps.component {
import flash.display.BitmapData;
import flash.events.MouseEvent;

import mx.core.DragSource;
import mx.managers.DragManager;

import spark.components.Image;
import spark.components.Label;

import wps.constant.DragConst;

public class DragableLabel extends Label {
	
	//--------------------------------------------------------------------------
	//
	// Event handlers
	//
	//--------------------------------------------------------------------------
	
	private function mouseDownHandler(e:MouseEvent):void {
		var initiator:Label = e.currentTarget as Label;
		
		var ds:DragSource = new DragSource();
		ds.addData(initiator, DragConst.TEXT);
		ds.addData(initiator.mouseX, DragConst.XOFFSET);
		ds.addData(initiator.mouseY, DragConst.YOFFSET);
		ds.addData(initiator.width, DragConst.WIDTH);
		ds.addData(initiator.height, DragConst.HEIGHT);
		
		var bmdata:BitmapData = new BitmapData(initiator.width, initiator.height, true, 0x00000000);
		bmdata.draw(initiator);
		
		var dragImage:Image = new Image();
		dragImage.source = bmdata;
		
		DragManager.doDrag(initiator, ds, e, dragImage, 0, 0, 1);
	}
	
	//--------------------------------------------------------------------------
	//
	// Constructor
	//
	//--------------------------------------------------------------------------
	
	public function DragableLabel() {
		super();
		
		addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
	}
	
}
}
